import { Component, Injector, ViewEncapsulation, ViewChild, ElementRef, OnInit } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ComboboxItemDto, SideTaskServiceProxy, ReceiveTaskInput, WorkingTimeServiceProxy, UserWorkingTimeDto, PipelineNodesServiceProxy, OrganizationUnitServiceProxy } from '@shared/service-proxies/service-proxies';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import * as moment from 'moment';
import { finalize } from 'rxjs/operators';
import { PutIntoProductionModalComponent } from '@app/plan/maintasks/put-into-production-modal.component';
import { MenuItem } from 'primeng/api';

@Component({
  templateUrl: './userworking.component.html',
  styleUrls: ['./userworking.component.less'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class UserworkingComponent extends AppComponentBase implements OnInit {
  @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginator') paginator: Paginator;

  dateRange: Date[];
  advancedFiltersAreShown = false;
  en: any;
  filterText = '';
  date:Date;
  orgid:ComboboxItemDto;
  data=new Array<UserWorkingTimeDto>();
  teamGroups: ComboboxItemDto[] = [];

  constructor(
    injector: Injector,
    private _workingTimeServiceProxy: WorkingTimeServiceProxy,
    private _organizationUnitServiceProxy: OrganizationUnitServiceProxy,
  ) {
    super(injector);
  }

  ngOnInit() {

    this.en = {
      firstDayOfWeek: 0,
      monthNames: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
      monthNamesShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
      dateFormat: 'yy-mm',
      weekHeader: 'Wk'
    };
    this._organizationUnitServiceProxy.getTeamGroups()
    .subscribe((result) => {
      this.teamGroups=result.items;
      this.orgid=this.teamGroups[0]
      this.getWorking();
    });

  }
  getWorking(event?: LazyLoadEvent) {
    var start=undefined;
      var end=undefined;
    if(this.dateRange!=undefined)
    {
      start=moment(this.dateRange[0]);
      end=moment(this.dateRange[1]);
    }
    this._workingTimeServiceProxy.getUserWorkingTimes(
      Number.parseInt(this.orgid.value),
      start,
      end
    ).subscribe(result => {
      this.data=result.items
    });
  }
}
